#include<iostream>

#include<stdio.h>

#include<vector>

#include<unistd.h>

#include<pthread.h>

using namespace std;

pthread_mutex_t MT = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t CD = PTHREAD_COND_INITIALIZER;

int num = 0;

struct task
{
    task(const string& str): _name(str)
    {
    }
    string _name;
    pthread_t _PT;
};

void* my_thread(void* arg)
{
    task* tk = static_cast<task*>(arg);
    while(1)
    {
        pthread_mutex_lock(&MT);
        pthread_cond_wait(&CD, &MT);
        cout << tk->_name << ", " << "num：" << num++ << endl;
        pthread_mutex_unlock(&MT);
    }
}

int main()
{
    vector<task*> arr;
    for(int i = 0; i < 10; ++i)
    {
        task* tk = new task("thread");
        tk->_name += i + '0';
        pthread_create(&(tk->_PT), nullptr, my_thread, (void*)tk);
        usleep(1000);
    }

    while(1)
    {
        sleep(1);
        pthread_mutex_lock(&MT);
        cout << "The signal has been sent" << endl;
        pthread_mutex_unlock(&MT);
        pthread_cond_broadcast(&CD);
    }
    return 0;
}